package com.example.homework.h2021_04_28;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.homework.R;
import com.example.homework.h2021_04_28.fragment.CircleFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class HomeworkActivity extends AppCompatActivity {

    //页面滑动
    private ViewPager viewPager;

    //显示的页面集合
    private List<Fragment> fragments;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_homework);
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_view);
        bottomNavigationView.setItemIconTintList(null);
        viewPager = findViewById(R.id.vp_main);
        fragments = new ArrayList<>();
        fragments.add(new CircleFragment());
        //设置适配器
        viewPager.setAdapter(new CirclePageAdapter(getSupportFragmentManager()));
    }

    class CirclePageAdapter extends FragmentPagerAdapter{

        public CirclePageAdapter(@NonNull FragmentManager fm) {
            super(fm);
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }
    }
}
